feat(ledger): audit FAILURE and DENIED outcomes for ledger writes - #137
Merged
Conversation
Record a committed FAILURE audit row from the global exception handler in a REQUIRES_NEW transaction so it survives the business rollback, and a DENIED row from a Spring Security AccessDeniedHandler. The SUCCESS path from #49 is unchanged. The audit write is observability only and never masks the client 4xx/403 response. Closes #133
| } catch ( | ||
| @Suppress("TooGenericExceptionCaught") ex: RuntimeException, | ||
| ) { | ||
| log.warn("audit DENIED write failed for {} {}", request.method, request.requestURI, ex) |
| } catch ( | ||
| @Suppress("TooGenericExceptionCaught") ex: RuntimeException, | ||
| ) { | ||
| log.warn("audit FAILURE write failed for {} {}", request.method, request.requestURI, ex) |
added 2 commits
June 15, 2026 18:53
FailureAuditIT requests now send a bearer token (were 401), and both ITs use UUID correlation ids so CorrelationIdFilter honors the inbound header (it canonicalizes only valid UUIDs), making the per-test row filter match.
…ntainer connection exhaustion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Additive continuation of #49 (SUCCESS-path audit). Records the two outcomes #49 deferred:
audit_eventsrow withresult=FAILUREfromGlobalExceptionHandlerin aREQUIRES_NEWtransaction, so it survives the business rollback.result=DENIEDrow from a Spring SecurityAccessDeniedHandler.The SUCCESS path from #49 is unchanged. The audit write is observability only: a failing audit write is swallowed-and-logged and never converts a 4xx/403 into a 500.
How
AuditTrailWriter.recordOutcome(record, result)(@Transactional(REQUIRES_NEW), no active-tx requirement) alongside the unchanged in-transactionrecord(); sharedtoEntitypreserves Write audit_events row per ledger write (actor, correlation, request hash) #49 payload semantics.FailureAuditRecordergates on a closedProblemTypeallowlist (validation/malformed/read-not-found excluded) plus anAuditEndpointResolver(write endpoints only); request hash from the idempotency body attribute.AuditingAccessDeniedHandlerwired via.exceptionHandling{}. No production authorization policy is added (that is Configure Spring Security resource server (Keycloak JWT) #47/Per-endpoint Keycloak scope authorization (ledger:read / ledger:write) #48); DENIED is proven via an integration test that fires the real handler through a real 403.ProblemType.ACCESS_DENIEDadded for the RFC 7807 403 body (runtime-only, no OpenAPI change).sha256Hexextracted toRequestHashing(shared with idempotency, no duplication).Tests
Unit: resolver, recorder (allowlist + hash + swallow-log), access-denied handler (DENIED + 403 + swallow-log),
recordOutcome. Integration:FailureAuditIT(unbalanced post -> committed FAILURE, reverse-of-unknown, validation-400 not audited),DeniedAuditIT(403 -> DENIED, 401 not audited). No migration, no entity change.Closes #133